    <form action="" method="post" id="frmCompany"  name="frmCompany">
        <?php
            $term = get_term($_GET['cat_id'], $_GET['taxonomy']);
        ?>
        <h2><?php print $term->name; ?> </h2>	
        <?php 
            if($_POST['btnUpdate']) {
                foreach($_POST['chk_field'] as $id => $field_id){
                    
                    $cat_id = $_GET['cat_id'];
                    //$field_id,
                    $required   = ($_POST['chk_requried_'.$field_id]==1)?1:0;
                    $partner    = ($_POST['chk_partner_'.$field_id]==1)?1:0;
                    $sort       = ($_POST['chk_sort_'.$field_id]==1)?1:0;
                    $search     = ($_POST['chk_search_'.$field_id]==1)?1:0;
                    $keyword    = ($_POST['chk_keyword_'.$field_id]==1)?1:0;  
                    
                    $sql = "SELECT count(*) FROM ". $wpdb->prefix."category_fields 
                            WHERE category_id=".$_GET['cat_id']." AND field_id=".$field_id;
                    $db_count =  $wpdb->get_var($sql);
            
                    if($db_count<=0){
                        $sql = "INSERT INTO ". $wpdb->prefix."category_fields 
                                    SET category_id=$cat_id, field_id=$field_id,
                                        required=$required, partner=$partner, sort=$sort, search=$search, keyword=$keyword";
                    } else {
                        $sql = "UPDATE ". $wpdb->prefix."category_fields 
                                    SET category_id=$cat_id, field_id=$field_id,
                                        required=$required, partner=$partner, sort=$sort, search=$search, keyword=$keyword
                                WHERE id = ".$_POST['hid_ID_'.$field_id];               
                    }
                    $wpdb->query($sql);
                }                
            }            
        ?> 	
        <div id="table-company">            
            <div class="header row">                
                <div class="col2 col">#</div>
                <div class="col4 col">Name</div>
                <div class="col7 col">Choose<font color="#bd0000">*</font></div>
                <div class="col7 col">Required</div>
                <div class="col7 col">For Partners</div> 
                <div class="col7 col">Sort</div>               
                <div class="col7 col">Search</div>
                <div class="col7 col">Keyword</div>                
            </div>
            <?php            
             $sql = "SELECT * FROM ".$wpdb->prefix.'content_fields ORDER BY weight';
             $db_fields = $wpdb->get_results($sql);
             $j = 1;
             ?>            
             <?php 
             foreach( $db_fields as $field){ 
                    $sql = "SELECT * FROM ". $wpdb->prefix."category_fields 
                            WHERE category_id=".$_GET['cat_id']." AND field_id=".$field->id;
                    $db_row =  $wpdb->get_row($sql);
                    $choose_checked     = ($db_row)?'checked = true':'';
                    $required_checked   = ($db_row->required==1)?'checked = true':'';
                    $sort_checked       = ($db_row->sort==1)?'checked = true':'';
                    $partner_checked    = ($db_row->partner==1)?'checked = true':'';
                    $search_checked     = ($db_row->search==1)?'checked = true':'';
                    $keyword_checked    = ($db_row->keyword==1)?'checked = true':'';
             ?>
              <div class="row">                
                <div class="col2 col"><?php print $j++;?></div>
                <div class="col4 col"><?php print $field->field_label;?><input type="hidden" name="hid_ID_<?php print $field->id;?>" value="<?php print ($db_row->id>0?$db_row->id:0);?>" /></div>
                <div class="col7 col"><input <?php print $choose_checked;?> class="chk_item" type="checkbox" id="chk_field<?php print $field->id;?>" name="chk_field[]" value="<?php print $field->id;?>"></div>
                <div class="col7 col"><input <?php print $required_checked ;?> class="chk_item" type="checkbox" id="chk_requried_<?php print $field->id;?>" name="chk_requried_<?php print $field->id;?>" value="1"></div>
                <div class="col7 col"><input <?php print $partner_checked;?> class="chk_item" type="checkbox" id="chk_partner_<?php print $field->id;?>" name="chk_partner_<?php print $field->id;?>" value="1"></div> 
                <div class="col7 col"><input <?php print $sort_checked;?> class="chk_item" type="checkbox" id="chk_sort_<?php print $field->id;?>" name="chk_sort_<?php print $field->id;?>" value="1"></div>               
                <div class="col7 col"><input <?php print $search_checked;?> class="chk_item" type="checkbox" id="chk_search_<?php print $field->id;?>" name="chk_search_<?php print $field->id;?>" value="1"></div>
                <div class="col7 col"><input <?php print $keyword_checked;?> class="chk_item" type="checkbox" id="chk_keyword_<?php print $field->id;?>" name="chk_keyword_<?php print $field->id;?>" value="1"></div>                
             </div>
             <?php } ?>
        </div>
        <div class="footer">           
            <input type="submit" value="Save Field Settings" id="btnUpdate" name="btnUpdate" class="button">
        </div>
    </form> 
     
 <script type="text/javascript">
        (function($){
            $(document).ready(function() {                
                 $('#btnAddCategory').click(function(){                        
                        window.location = "?page=accm_Site_Manager&tabmenu=<?php print $_GET['tabmenu'];?>&act=add#field";
                 });  
            }); 
            $('#chk_all').click(function(){               
                if (this.checked) 
                    $('.chk_item').attr('checked',true);
                else
                   $('.chk_item').removeAttr('checked'); 
            });  
            $('#btnDelete').click(function(){
                 chk = false;
                 $('.chk_item').each(function(){
                    if(this.checked) chk = true;
                 });
                 if (!chk) {
                    alert('Please choose item to delete!');
                    return false;
                 } else {
                    return confirm('Are you sure detele!');
                 }
            }); 
            $('#btnApprove').click(function(){
                 chk = false;
                 $('.chk_item').each(function(){
                    if(this.checked) chk = true;
                 });
                 if (!chk) {
                    alert('Please choose item to delete!');
                    return false;
                 } else {
                    return true;
                 }
            }); 
            $('#btnDeny').click(function(){
                 chk = false;
                 $('.chk_item').each(function(){
                    if(this.checked) chk = true;
                 });
                 if (!chk) {
                    alert('Please choose item to delete!');
                    return false;
                 } else {
                    return true;
                 }
            }); 
        })(jQuery);
     </script>      